package com.cxhc.app.api.hcdoc;

import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletResponse;

import com.cxhc.common.core.domain.R;
import com.cxhc.system.domain.hcdoc.HdPetitionAgent;
import com.cxhc.system.service.hcdoc.IHdPetitionAgentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.cxhc.common.core.controller.BaseController;
import com.cxhc.common.core.domain.AjaxResult;
import com.cxhc.common.utils.poi.ExcelUtil;
import com.cxhc.common.core.page.TableDataInfo;

/**
 * 信访信息Controller
 * 
 * @author Dhq
 * @date 2024-09-26
 */
@RestController
@RequestMapping("/api/hcDoc/petitionAgent")
public class HdPetitionAgentController extends BaseController
{
    @Autowired
    private IHdPetitionAgentService hdPetitionAgentService;

    /**
     * 查询信访信息列表
     */
    @GetMapping("/list")
    public TableDataInfo list(HdPetitionAgent hdPetitionAgent)
    {
        startPage();
        List<HdPetitionAgent> list = hdPetitionAgentService.selectHdPetitionAgentList(hdPetitionAgent);
        return getDataTable(list);
    }

    /**
     * 信访统计 按类型统计
     */
    @GetMapping("/statistics")
    public R<Map<Integer, Long>> statistics(HdPetitionAgent hdPetitionAgent)
    {
        return R.ok(hdPetitionAgentService.statisticsByPetitionType(hdPetitionAgent));
    }

    /**
     * 导出信访信息列表
     */
    @GetMapping("/export")
    public void export(HttpServletResponse response, HdPetitionAgent hdPetitionAgent)
    {
        List<HdPetitionAgent> list = hdPetitionAgentService.selectHdPetitionAgentList(hdPetitionAgent);
        ExcelUtil<HdPetitionAgent> util = new ExcelUtil<HdPetitionAgent>(HdPetitionAgent.class);
        util.exportExcel(response, list, "信访信息数据","信访信息数据");
    }

    /**
     * 获取信访信息详细信息
     */
    @GetMapping(value = "/detail/{petitionNo}")
    public AjaxResult getInfo(@PathVariable("petitionNo") String petitionNo)
    {
        return success(hdPetitionAgentService.selectHdPetitionAgentByPetitionNo(petitionNo));
    }

    /**
     * 新增信访信息
     */
    @PostMapping("/insert")
    public AjaxResult add(@RequestBody HdPetitionAgent hdPetitionAgent)
    {
        return toAjax(hdPetitionAgentService.insertHdPetitionAgent(hdPetitionAgent));
    }

    /**
     * 修改信访信息
     */
    @PostMapping("/update")
    public AjaxResult edit(@RequestBody HdPetitionAgent hdPetitionAgent)
    {
        return toAjax(hdPetitionAgentService.updateHdPetitionAgent(hdPetitionAgent));
    }

    /**
     * 删除信访信息
     */

    @GetMapping(value = "/delete/{petitionNo}")
    public AjaxResult remove(@PathVariable String petitionNo)
    {
        return toAjax(hdPetitionAgentService.deleteHdPetitionAgentByPetitionNo(petitionNo));
    }
}
